/**
 * 
 */
package com.jie.eclipse.pan.dao;

import com.jie.eclipse.pan.data.BaseDataEntity;
import com.jie.eclipse.pan.utils.StringBuilderEx;

/**
 * @author yanjie
 *
 */
public class BaseDao {
	
	public String getConditionSql(BaseDataEntity row){
		if(row.isNullOrEmpty("op")) return "";
		StringBuilderEx whr = new StringBuilderEx();
		whr.Append("\r\nif(!form.isNullOrEmpty(\"%1$s\")){",row.gpsv("name"));
			String opstr = row.gpsv("op");
			if(opstr.equalsIgnoreCase("starwith")){
				whr.Append("\r\n	sql.Append(\" and %1$s%2$s %3$s '%%%%%%1\\$s' \",form.gpsv(\"%4$s\"));",
						row.gpsv("tablepix").length() == 0? "" : row.gpsv("tablepix")+".",
						row.gpsv("columnalias"),
						"like",
						row.gpsv("name"));
			}else if(opstr.equalsIgnoreCase("endwith")){
				whr.Append("\r\n	sql.Append(\" and %1$s%2$s %3$s '%%1\\$s%%%%' \",form.gpsv(\"%4$s\"));",
						row.gpsv("tablepix").length() == 0? "" : row.gpsv("tablepix")+".",
						row.gpsv("columnalias"),
						"like",
						row.gpsv("name"));
			}else if(opstr.equalsIgnoreCase("like")){
				whr.Append("\r\n	sql.Append(\" and %1$s%2$s %3$s '%%%%%%1\\$s%%%%' \",form.gpsv(\"%4$s\"));",
						row.gpsv("tablepix").length() == 0? "" : row.gpsv("tablepix")+".",
						row.gpsv("columnalias"),
						"like",
						row.gpsv("name"));
			}else{
				whr.Append("\r\n	sql.Append(\" and %1$s%2$s %3$s '%%1\\$s' \",form.gpsv(\"%4$s\"));",
						row.gpsv("tablepix").length() == 0? "" : row.gpsv("tablepix")+".",
						row.gpsv("columnalias"),
						opstr,
						row.gpsv("name"));
				
			}
			
		whr.Append("\r\n}");
		return whr.toString();
	}
}
